import Loading from 'Comps/Loading/GoodsLoading'
import { mapGetters } from 'vuex'
import { isPc, isMobile, isWxBrowser } from '@/utils'
import $API from '@/api/services'
const shareurlSend = location.origin + location.pathname

export default {
  components: {
    Loading,
  },
  data() {
    return {
      isShowLoading: true,
      isShowPic: false,
      isShow: false,
    }
  },
  methods: {
    closeLoading() {
      this.isShowLoading = false
    },
    // 微信分享
    getWXShareData(info) {
      if (info) {
        document.title = info.name || ''
      }
      if (!isWxBrowser()) return
      let wx = window.wx
      $API('getOverviewWXShare', [shareurlSend]).then(res => {
        let data = res.data
        if(res.code == 100) {
          wx.config({
            debug: false,
            // appId: data.appid,
            // timestamp: data.timestamp,
            // nonceStr: data.nonce,
            // signature: data.signature,
            appId: data.appId,
            timestamp: data.timestamp,
            nonceStr: data.nonceStr,
            signature: data.signature,
            jsApiList: [
              'onMenuShareTimeline',
              'openLocation',
              'getLocation',
              'onMenuShareAppMessage',
              'onMenuShareQQ',
              'onMenuShareQZone',
              'onMenuShareWeibo',
              'showOptionMenu'
            ]
          })

          let shareContent = {
            title: info.name || '',
            desc: info.share_conent || '',
            link: window.location.href,
            imgUrl: info.full_logo || '',
            success: function() {},
            cancel: function() {}
          }
          // console.log(shareContent)

          wx.ready(function() {
            wx.showOptionMenu()

            wx.onMenuShareTimeline(shareContent)

            //分享给朋友
            wx.onMenuShareAppMessage(shareContent)

            //QQ
            wx.onMenuShareQQ(shareContent)

            //QQ微博
            wx.onMenuShareWeibo(shareContent)

            //QQ空间
            wx.onMenuShareQZone(shareContent)

          })

          wx.error(function(res) {
            console.log(res)
          })
        }
      })
    }
  },
  computed: {
    ...mapGetters(['loadInfo']),
    getLoadImage() {
      if (!this.loadInfo) return false
      if (this.loadInfo) {
        if (this.loadInfo.load_type == 1) {
          return true
        } else {
          if (this.loadInfo && this.loadInfo.load_type == 0) {
            if(isPc() && this.loadInfo.pc_load_img) {
              return this.loadInfo.pc_load_img
            }
            if(isMobile() && this.loadInfo.load_img) {
              return this.loadInfo.load_img
            }
          }
        }
      }
      
    },
  },
}
